package com.loobot.album.controller;

import com.loobot.album.dao.model.Picture;
import com.loobot.album.net.RestResult;
import com.loobot.album.net.RestResultGenerator;
import com.loobot.album.net.param.request.GetPictures;
import com.loobot.album.service.PictureService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author: Ike.Fan
 * @date: 2019/3/14.
 */
@Api("相片api")
@RequestMapping("picture")
@RestController
public class PicController {
    @Autowired
    PictureService pictureService;


    @ApiOperation(value = "添加图片到指定相册")
    @PostMapping("/add/pic")
    public RestResult<Picture> addPic(@RequestParam("albumUUID") String albumUUID,
                                     @RequestParam("userId") String userId, MultipartFile file){
        return RestResultGenerator.genSuccessResult(pictureService.addPic(albumUUID, userId, file));
    }

    @ApiOperation(value = "删除相册中指定相片")
    @PostMapping("/delete/pic/{id}")
    public RestResult<Integer> deletePic(@PathVariable(value = "picId") long picId){
        return RestResultGenerator.genSuccessResult(pictureService.delete(picId));
    }

    @ApiOperation(value = "分页获取相册中图片")
    @PostMapping("/get")
    public RestResult<List<Picture>> getPic(@RequestBody GetPictures getPictures){
        return RestResultGenerator.genSuccessResult(pictureService.getPictures(getPictures));
    }

}
